import { _httpClient } from "@/libs/api";

/*
 * oss put操作
 */
function putObj(filePath) {
  try {
    let res = _httpClient.postFile(
      _httpClient.getApiPrefix() + "/minio/oss/putObject",
      {
        files: {
          file: filePath,
        },
      }
    );
    if (res.code === 200) {
      return res.fileUrl;
    } else {
      api.toast(JSON.stringify(res));
    }
  } catch (e) {
    api.toast(JSON.stringify(e));
  }
}

/*
 * oss delete操作
 */
function delObj(filename) {
  try {
    let res = _httpClient.delete(
      _httpClient.getApiPrefix() + "/minio/oss/" + filename,
      {}
    );
    if (res.code === 200) {
      api.toast(res.msg);
    } else {
      api.toast(JSON.stringify(res));
    }
  } catch (e) {
    api.toast(JSON.stringify(e));
  }
}

export const _ossClient = {
  async putObject(url) {
    return await putObj(url);
  },
  async deleteObject(url, data) {
    return await delObj({ url, data });
  },
};
